﻿namespace Microsoft.VisualStudio.IDE.ToolboxControlsInstaller
{
    using Microsoft.Win32;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.CompilerServices;

    internal class RegisteredAssembly : IEquatable<RegisteredAssembly>
    {
        public RegisteredAssembly(System.Reflection.AssemblyName assemblyName)
        {
            this.AssemblyName = assemblyName;
            this.RegisteredControls = new List<RegisteredControl>();
            this.ToolboxItemCategories = new Dictionary<string, string>();
        }

        public virtual bool AddItemsToToolbox(IServiceProvider provider, RegistryKey ApplicationRegistryRoot)
        {
            return false;
        }

        public bool Equals(RegisteredAssembly other)
        {
            if (other == null)
            {
                return false;
            }
            return (((this.RegistryHash == null) && (other.RegistryHash == null)) || (((this.RegistryHash != null) && (other.RegistryHash != null)) && this.RegistryHash.SequenceEqual<byte>(other.RegistryHash)));
        }

        protected string ExtractFullTypeName(string typeName)
        {
            typeName = typeName.Substring(0, typeName.IndexOf(','));
            return typeName;
        }

        protected string ExtractShortTypeName(string typeName)
        {
            typeName = typeName.Substring(0, typeName.IndexOf(','));
            typeName = typeName.Substring(typeName.LastIndexOf('.') + 1);
            return typeName;
        }

        public System.Reflection.AssemblyName AssemblyName { get; set; }

        public string DefaultCategory { get; set; }

        public virtual string Identifier
        {
            get
            {
                return string.Empty;
            }
        }

        public List<RegisteredControl> RegisteredControls { get; set; }

        public byte[] RegistryHash { get; set; }

        public string TargetFramework { get; set; }

        public Dictionary<string, string> ToolboxItemCategories { get; set; }
    }
}

